package com.example.seataordersys.api;

import com.example.seataordersys.service.OrderService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/api/order")
@RestController
@Slf4j
public class OrderApi {

    @Autowired
    private OrderService orderService;

    /**
     * 下单接口
     * @param userId   用户id
     * @param productId  产品id
     * @param count  下单个数
     * @return
     */
    @GetMapping(value = "/debit")
    public String debit(@RequestParam Long userId, @RequestParam Long productId, @RequestParam Integer count) {
        log.info("order XID :{}", RootContext.getXID());
        orderService.create(userId, productId, count);
        return "ok";
    }





}
